package service.impl;

import java.sql.SQLException;
import java.util.List;

import module.Customers;
import module.HousePhoto;
import module.Logs;
import module.NewHouse;

import org.apache.log4j.Logger;

import service.NewHouseService;
import domain.vo.queryObject;

public class NewHouseServiceImpl  extends NewHouseService{
	private Logger logger = Logger.getLogger(NewHouseServiceImpl.class.getName());
	/* (非 Javadoc) 
	* <p>Title: getById</p> 
	* <p>Description: </p> 
	* @param id
	* @return
	* @throws SQLException 
	* @see service.basicService#getById(java.lang.String) 
	*/ 
	
	
	@Override
	public NewHouse getById(String id) throws SQLException {
		return newHouseDAO.getById(id);
	}

	/* (非 Javadoc) 
	* <p>Title: getAll</p> 
	* <p>Description: </p> 
	* @return
	* @throws SQLException 
	* @see service.basicService#getAll() 
	*/ 
	
	
	@Override
	public List<NewHouse> getAll() throws SQLException {
		// TODO Auto-generated method stub
		return super.getAll();
	}

	/* (非 Javadoc) 
	* <p>Title: insertObject</p> 
	* <p>Description: </p> 
	* @param t
	* @throws SQLException 
	* @see service.basicService#insertObject(java.lang.Object) 
	*/ 
	
	
	@Override
	public void insertObject(NewHouse t) throws SQLException {
		try {
			sqlMapClient.startTransaction();
			newHouseDAO.insertT(t);
			sqlMapClient.startBatch();
			logger.debug("保存图片");
			for (HousePhoto  p : t.getHousePhotos()) {
				p.setHouseid(t.getId());
				hpDAO.insertT(p);
			}			
			sqlMapClient.executeBatch();
			sqlMapClient.commitTransaction();
		} finally {
			sqlMapClient.endTransaction();
		}
	}

	/* (非 Javadoc) 
	* <p>Title: updateObject</p> 
	* <p>Description: </p> 
	* @param t
	* @throws SQLException 
	* @see service.basicService#updateObject(java.lang.Object) 
	*/ 
	
	
	@Override
	public void updateObject(NewHouse t) throws SQLException {
		try {
			sqlMapClient.startTransaction();
			newHouseDAO.updateT(t);
			sqlMapClient.startBatch();
			logger.debug("保存修改日志");
			for (Logs log : t.getHouseLogs()) {
				log.setFkid(t.getId());
				logsDAO.insertT(log);
			}
			logger.debug("保存图片");
			for (HousePhoto  p : t.getHousePhotos()) {
				p.setHouseid(t.getId());
				hpDAO.insertT(p);
			}
			sqlMapClient.executeBatch();
			sqlMapClient.commitTransaction();
		} finally {
			sqlMapClient.endTransaction();
		}
	}

	/* (非 Javadoc) 
	* <p>Title: deleteT</p> 
	* <p>Description: </p> 
	* @param id
	* @throws SQLException 
	* @see service.basicService#deleteT(int) 
	*/ 
	
	
	@Override
	public void deleteT(int id) throws SQLException {
		// TODO Auto-generated method stub
		super.deleteT(id);
	}

	/* (非 Javadoc) 
	* <p>Title: getObjectByQueryObject</p> 
	* <p>Description: </p> 
	* @param queryObject
	* @return
	* @throws SQLException 
	* @see service.basicService#getObjectByQueryObject(domain.vo.queryObject) 
	*/ 
	
	
	@Override
	public List<NewHouse> getObjectByQueryObject(queryObject queryObject)
			throws SQLException {
		// TODO Auto-generated method stub
		return newHouseDAO.getObjectByQueryObject(queryObject);
	}

	/* (非 Javadoc) 
	* <p>Title: countByQueryObject</p> 
	* <p>Description: </p> 
	* @param queryObject
	* @return
	* @throws SQLException 
	* @see service.basicService#countByQueryObject(domain.vo.queryObject) 
	*/ 
	
	
	@Override
	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return newHouseDAO.countByQueryObject(queryObject);
	}

}
